package initalize

import (
	_ "base-web/docs"
	"base-web/global"
	"base-web/middleware"
	"base-web/router"
	"fmt"
	"github.com/gin-gonic/gin"
	ginSwagger "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	"net/http"
)

//初始化总路由
func Routers() *gin.Engine {
	//初始化gin服务
	var r = gin.Default()
	//设置运行模式
	gin.SetMode(global.BASE_CONFIG.System.SetMod)

	//注册swaager
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	r.Use(middleware.Cors())    //处理跨域
	r.Use(middleware.Logging()) //处理日志

	//注册文件路由 <http访问路径> <文件存放位置>
	r.StaticFS("/static/upload", http.Dir("./static/upload"))
	fmt.Printf("自动化文档地址：http://127.0.0.1:%s/swagger/index.html\n", global.BASE_CONFIG.System.Addr)
	//注册路由
	ApiGroup := r.Group("/api/v1/")
	router.InitUserRouter(ApiGroup) //注册用户路由
	return r
}
